package com.drawquest.gui.components;

import com.drawquest.data.Comment;
import com.drawquest.gui.panels.BigCommentsPanel;
import com.gooddies.swing.swypepanel.SwypePanel;
import com.gooddies.wiring.Wiring;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JComponent;

public class CommentPartPanel extends javax.swing.JPanel {

    private String commentId;
    private Comment comment;

    public CommentPartPanel() {
        initComponents();
        avatarImagePanel.setVerticalGap(2);
        avatarImagePanel.setHorizontalGap(2);
        imagePanel.setVerticalGap(2);
        imagePanel.setHorizontalGap(2);
        addDefaultMouseHandler(avatarImagePanel);
        addDefaultMouseHandler(imagePanel);
        addDefaultMouseHandler(avatarLabel);
        addDefaultMouseHandler(titleLabel);
        addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                showComment();
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            }
        });
    }

    private void showComment() {
        BigCommentsPanel commentPanel=Wiring.getComponent(BigCommentsPanel.class);
        commentPanel.setComment(comment);
        Wiring.getComponent(SwypePanel.class).pushComponent(commentPanel);
    }
    
    private MouseAdapter mlistener = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            CommentPartPanel.this.dispatchEvent(e);
        }
    };

    private void addDefaultMouseHandler(JComponent c) {
        if (c.getMouseListeners().length == 0) {
            c.addMouseListener(mlistener);
        }
        if (c.getMouseMotionListeners().length == 0) {
            c.addMouseMotionListener(mlistener);
        }
    }

    public void setComment(Comment comment) {
        this.comment = comment;
    }

    public String getCommentId() {
        return commentId;
    }

    public void setCommentId(String commentId) {
        this.commentId = commentId;
    }

    public void setAvatarLabel(String avatarLabelText) {
        avatarLabel.setText(avatarLabelText);
    }

    public void setAvatarPic(String avatarUrl) {
        avatarImagePanel.setUrl(avatarUrl);
    }

    public void setQuestTitle(String title) {
        titleLabel.setText(title);
    }

    public void setQuestImage(String questImage) {
        imagePanel.setUrl(questImage);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        titleLabel = new javax.swing.JLabel();
        avatarImagePanel = new com.drawquest.gui.components.ImagePanel();
        avatarLabel = new javax.swing.JLabel();
        imagePanel = new com.drawquest.gui.components.ImagePanel();
        jLabel1 = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        setMinimumSize(new java.awt.Dimension(400, 170));
        setPreferredSize(new java.awt.Dimension(400, 170));
        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titleLabel.setText("jLabel1");
        add(titleLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 0, 260, -1));

        avatarImagePanel.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout avatarImagePanelLayout = new javax.swing.GroupLayout(avatarImagePanel);
        avatarImagePanel.setLayout(avatarImagePanelLayout);
        avatarImagePanelLayout.setHorizontalGroup(
            avatarImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 63, Short.MAX_VALUE)
        );
        avatarImagePanelLayout.setVerticalGroup(
            avatarImagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 63, Short.MAX_VALUE)
        );

        add(avatarImagePanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 20, -1, -1));

        avatarLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        avatarLabel.setForeground(new java.awt.Color(0, 51, 255));
        avatarLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        avatarLabel.setText("avatar Label");
        avatarLabel.setToolTipText("");
        avatarLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        add(avatarLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 90, 80, 50));

        imagePanel.setBackground(new java.awt.Color(255, 255, 255));

        javax.swing.GroupLayout imagePanelLayout = new javax.swing.GroupLayout(imagePanel);
        imagePanel.setLayout(imagePanelLayout);
        imagePanelLayout.setHorizontalGroup(
            imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 288, Short.MAX_VALUE)
        );
        imagePanelLayout.setVerticalGroup(
            imagePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 128, Short.MAX_VALUE)
        );

        add(imagePanel, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 20, 290, 130));

        jLabel1.setText("   ");
        add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 150, -1, -1));
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.drawquest.gui.components.ImagePanel avatarImagePanel;
    private javax.swing.JLabel avatarLabel;
    private com.drawquest.gui.components.ImagePanel imagePanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel titleLabel;
    // End of variables declaration//GEN-END:variables
}
